<template>
  <div class="code">
    <el-table :data="dataList" v-loading="tableLoading" row-key="id" border style="width: 100%; ">
      <el-table-column prop="id" align="center" label="ID" width="190">
      </el-table-column>
      <el-table-column prop="levelName" align="center" label="等级名称">
      </el-table-column>
      <el-table-column prop="needInvite" align="center" label="直推需求人数">
      </el-table-column>
      <el-table-column prop="needUseAmount" align="center" label="升级需求的个人业绩">
      </el-table-column>
      <el-table-column prop="needTeamAmount" align="center" label="升级需求的小区团队业绩">
      </el-table-column>
      <el-table-column prop="teamWithdrawRate" align="center" label="团队奖励比例(%)">
      </el-table-column>
      <el-table-column prop="managerNeedLevel" align="center" label="升级董事所需对应等级">
      </el-table-column>
      <el-table-column prop="managerNeedNum" align="center" label="升级董事所需对应等级的人数">
      </el-table-column>
      <el-table-column prop="managerWithdrawRate" align="center" label="董事奖励比例">
      </el-table-column>
      <el-table-column prop="type" align="center" label="类型">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作" width="80">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 查看 -->
    <el-dialog :title="修改" :visible.sync="dialogVisible" width="50%">
      <el-form ref="form" :model="info" label-width="180px">
        <el-form-item label="等级名称">
          <el-input v-model="info.levelName"></el-input>
        </el-form-item>
        <el-form-item label="直推需求人数">
          <el-input v-model="info.needInvite"></el-input>
        </el-form-item>
        <el-form-item label="升级需求的个人业绩">
          <el-input v-model="info.needUseAmount"></el-input>
        </el-form-item>
        <el-form-item label="升级需求的小区团队业绩">
          <el-input v-model="info.needTeamAmount"></el-input>
        </el-form-item>
        <el-form-item label="团队奖励比例(%)">
          <el-input v-model="info.teamWithdrawRate"></el-input>
        </el-form-item>
        <el-form-item label="升级董事所需对应等级">
          <el-input v-model="info.managerNeedLevel"></el-input>
        </el-form-item>
        <el-form-item label="升级董事所需对应等级的人数">
          <el-input v-model="info.managerNeedNum"></el-input>
        </el-form-item>
        <el-form-item label="董事奖励比例">
          <el-input v-model="info.managerWithdrawRate"></el-input>
        </el-form-item>
        <el-form-item label="类型">
          <el-input v-model="info.type"></el-input>
        </el-form-item>
        <div style="width: 100%; text-align: right; margin-top: 30px;">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveForm">保 存</el-button>
        </div>
      </el-form>
    </el-dialog>


  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      params: {
        id: '',
        levelName: '',
        type: '',
        managerWithdrawRate: '',
        managerNeedNum: '',
        managerNeedLevel: '',
        teamWithdrawRate: '',
        needTeamAmount: '',
        needUseAmount: '',
        needInvite: '',
      },
      dialogVisible: false, // 控制修改页面的显示
      form: {},
      browse: null,
      dataList: [],
      tableLoading: false,
      info: {}
    }
  },
  mounted () {
    this.loadList()
  },
  methods: {
    // 获取信息
    loadList () {
      this.tableLoading = true
      seviceApi.otherStoreManagerRewardInfo(this.params).then(res => {
        if (res && res.status === 200) {
          console.log("获取配置信息:", res.data)
          this.dataList = res.data.data
        }
        this.tableLoading = false
      })
    },
    // BlurText(e){
    //   let boolean = new RegExp("^[0-9]*$").test(e.target.value)
    //   if(!boolean){
    //     e.target.value=0
    //     this.$message.warning('请输入正整数')
    //   }
    // },
    // focusText(e){
    // console.log(e.target.value)
    // e.target.value=0
    // },
    saveForm () {
      this.params = {
        id: this.info.id,
        levelName: this.info.levelName,
        managerWithdrawRate: this.info.managerWithdrawRate,
        managerNeedNum: this.info.managerNeedNum,
        managerNeedLevel: this.info.managerNeedLevel,
        teamWithdrawRate: this.info.teamWithdrawRate,
        needTeamAmount: this.info.needTeamAmount,
        needUseAmount: this.info.needUseAmount,
        needInvite: this.info.needInvite,
        type: this.info.type,
      }
      seviceApi.otherStoreManagerRewardSave(this.params).then(res => {
        console.log('保存配置信息:', res)
        if (res && res.data && res.data.code === 200) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.dialogVisible = false
        } else {
          this.$message({
            message: '操作失败',
            type: 'error'
          })
        }
      }).catch(error => {
        console.error('保存时发生错误', error)
        this.$message({
          message: '保存时发生错误',
          type: 'error'
        })
      })
    },
    // 修改
    edit (row) {
      this.dialogVisible = true
      this.info = row
    }
  }

}
</script>

<style lang="scss" scoped="scoped">
.top-size {
  margin-top: 3px;
}
.topstyle {
  margin-top: 30px;
}
.table {
  margin-top: 30px;
  // width: 55%;
  border: 1px solid rgba(228, 228, 228, 1);
  .top:last-child {
    border: none;
  }
  .top {
    border-bottom: 1px solid rgba(228, 228, 228, 1);
    display: flex;
    .item-content {
      display: flex;
      border: 1px solid rgba(228, 228, 228, 1);
      margin: 5px;
      input {
        width: 100px;
        box-shadow: none;
        outline: none;
        resize: none;
        border: none;
        -webkit-appearance: none;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        height: 30px;
      }
      div {
        background-color: #f2f2f2;
        width: 40px;
        text-align: center;
        font-size: 16px;
        padding-top: 5px;
        color: #999999;
      }
    }
    .item-title {
      width: 300px;
      padding: 15px 10px 10px 60px;
      text-align: right;
      background-color: rgba(242, 242, 242, 1);
      border-right: 1px solid rgba(228, 228, 228, 1);
      font-size: 14px;
      font-weight: 400;
      color: #666666;
    }
    .item-code {
      padding: 13px 5px 10px 30px;
      font-size: 14px;
      color: #666666;
    }
  }
}
.box {
  display: flex;
  .community {
    font-weight: bold;
    font-size: 14px;
    margin-right: 10px;
  }
  .title {
    font-size: 14px;
    color: #cccccc;
  }
}
</style>
